package com.chang.soul.service.imp;

import com.chang.soul.bean.AdminBean;
import com.chang.soul.bean.UserBean;
import com.chang.soul.service.ArticleService;
import com.chang.soul.service.UserService;
import com.chang.soul.dao.UserMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author xiaoqingyang@vip.henu.edu.cn
 * @date 2021/3/31 20:49
 */
/*@Service对应的是业务层Bean*/
@Service
/*@Slf4j是用作日志输出的，一般会在项目每个类的开头加入该注解*/
@Slf4j
public class UserServiceImp implements UserService {

    @Autowired
    UserMapper userMapper;

    @Override
    public List<UserBean> getAllUser() {
        return userMapper.getAllUser();
    }

    @Override
    public UserBean getUserByNickName(String nickName) {
        return userMapper.getUserByNickName(nickName);
    }

    @Override
    public UserBean getUserById(int id) {
        return userMapper.getUserById(id);
    }

    @Override
    public int getCountsByNickName(String nickname) {
        return userMapper.getCountsByNickName(nickname);
    }

    @Override
    public boolean insertUser(UserBean userBean) {
        try {
            userMapper.insertUser(userBean);
        }catch (Exception e){
            System.out.println(e);
            return false;
        }

        return true;
    }

    @Override
    public boolean deleteUserById(Integer id) {
        try {
            userMapper.deleteUserById(id);
        }catch (Exception e){
            System.out.println(e);
            return false;
        }
        return true;
    }

    @Override
    public boolean updateUser(UserBean userBean) {

        try {
            userMapper.updateUser(userBean);
        }catch (Exception e){
            System.out.println(e);
            return false;
        }
        return true;
    }

    @Override
    public Integer getCountByGender(Integer Gender) {
        return userMapper.getCountByGender(Gender);
    }

    /*@Override
    public boolean updateUserPassword(UserBean userBean) {

        try {
            userMapper.updateUserPassword(userBean);
        }catch (Exception e){
            System.out.println(e);
            return false;
        }
        return true;
    }*/
}
